<!-- TrainSubmitUserInfo.html -->
<!DOCTYPE html>
<html class="base_gary_bg_color">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>查看/修改个人信息</title>
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/base.css">
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/mui.picker.min.css"/>
		<script src="../../script/ui.js"></script>
		<style type="text/css" media="screen">
			.base_right_item {
				color: white;
			}
			.right_aligned_input {
				text-align: right;
			}
			a:active {
				color: #d9d9d9;
			}
			.mui-btn-blue {
				border: 1px solid #18b4ed;
				background-color: #18b4ed;
			}
		</style>
	</head>
	<body class="base_gary_bg_color">
		<div class="base_style_color" id='BarAppearance'></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar" >
			<a class="base_left_item" href="#" onclick="backClick()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span>我的资料</span>
			<a class="base_right_item" href="#" onclick="submitClick()" style="line-height: 44px"> 提交 </a>
		</div>
		<div class="base_content_div base_content_font"  >
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label class="base_grey">性别</label>
					<input id="user_sex" class="right_aligned_input base_content_font base_dark_grey" type="text" value="" placeholder="请选择性别" readonly>
				</div>
				<div class="mui-input-row">
					<label class="base_grey">出生年份</label>
					<input id="user_birthday" class="time_input right_aligned_input base_content_font base_dark_grey" type="number" placeholder="请选择出生年份" value="" data-options='' readonly>
				</div>
				<div class="mui-input-row">
					<label class="base_grey">QQ</label>
					<input id="qqnumber" class="right_aligned_input base_content_font base_dark_grey" type="tel" placeholder="请输入您的QQ号" maxlength="15">
				</div>
				<div class="mui-input-row">
					<label class="base_grey">手机号码</label>
					<input id="phonenumber" class="right_aligned_input base_content_font base_dark_grey" type="tel" placeholder="请输入您的联系电话" maxlength="11" onkeyup="this.value=this.value.replace(/\D/g,'')">
				</div>
			</form>
			<div id="company_detail" hidden="hidden">
				<div class="base_title_font base_dark_grey" style="padding: 10px 14px;">
					实习单位详情
				</div>
				<form class="mui-input-group">
					<div class="mui-input-row">
						<label class="base_grey">单位名称</label>
						<input id="companyname" class="right_aligned_input base_content_font base_light_gray" type="text" placeholder="暂无数据" readonly>
					</div>
					<div class="mui-input-row">
						<label class="base_grey">单位地址</label>
						<input id="companyaddress" class="right_aligned_input base_content_font base_light_gray" type="text" placeholder="暂无数据" readonly>
					</div>
					<div class="mui-input-row">
						<label class="base_grey">联系方式</label>
						<input id="comapnytel" class="right_aligned_input base_content_font base_light_gray" type="number" placeholder="暂无数据" readonly>
					</div>
					<div class="mui-input-row">
						<label class="base_grey">实习岗位</label>
						<input id="workname" class="right_aligned_input base_content_font base_light_gray" type="text" placeholder="暂无数据" readonly>
					</div>
					<div class="mui-input-row">
						<label class="base_grey">实习开始</label>
						<input id="shixi_start" class="time_input right_aligned_input base_content_font base_light_gray" type="text" placeholder="暂无数据" data-options='{"type":"date"}' readonly>
					</div>
					<div class="mui-input-row">
						<label class="base_grey">实习结束</label>
						<input id="shixi_end" class="time_input right_aligned_input base_content_font base_light_gray" type="text" placeholder="暂无数据" data-options='{"type":"date"}' readonly>
					</div>
				</form>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/jquery-weui.min.js"></script>
	<script type="text/javascript" src="../../script/mui.min.js"></script>
	<script type="text/javascript" src="../../script/mui.dtpicker.js"></script>
	<script type="text/javascript" src="../../script/mui.picker.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script type="text/javascript">
		apiready = function() {
			initHeaderUI();
			setupData();
			setupUserType();
			customUI();
		}
		function setupUserType() {
			var userType = $api.getStorage('userType');
			if (userType == 1) {//教师
				$('#company_detail').hide();
			} else {
				$('#company_detail').show();
			}
		}

		function setupData() {
			cfnetppPOST(urlApplst, {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid')
			}, true, function(data, status) {
//					alert("获取"+JSON.stringify(data));
//			      	alert("获取"+JSON.stringify(data));
				if (status == 'success') {
					if (data.status == 1) {
						var jsonData = data.json;
						setupUserData(jsonData);
					} else {
					}
				} else {
				}
			});
		}

		function setupUserData(data) {
			$('#user_sex').val(data.usersex == 1 ? '男' : '女');
			$('#user_birthday').val(data.birthday);
			$('#qqnumber').val(data.qqnumber);
			$('#phonenumber').val(data.telephone);
			$('#companyname').val(data.corpname);
			$('#companyaddress').val(data.address);
			$('#comapnytel').val(data.mobile);
			$('#workname').val(data.workname);
			$('#shixi_start').val(timeStringWithTimeStamp(data.starttime));
			$('#shixi_end').val(timeStringWithTimeStamp(data.endtime));
		}


		$(document).ready(function() {
			customUI();
		});
		function customUI() {
			setupSexPicker();
			setupYearPicker();
		}

		//设置QQ号输入限制
		function setupQQ() {
		}

		function setupSexPicker() {
			$("#user_sex").picker({
				title : "请选择性别",
				cols : [{
					textAlign : 'center',
					values : ['男', '女']
				}],
				onChange : function(p, v, dv) {
					console.log('p:' + p, 'v:' + v, 'dv' + dv);
				},
				onClose : function(p, v, d) {
					console.log("close");
				}
			});
		}

		function setupYearPicker() {
			var now = new Date();
			var nowYear = now.getFullYear();
			var minYear = 1900;
			var yearArr = new Array();
			for (var i = 0; i <= nowYear - minYear; i++) {
				yearArr.push(nowYear - i);
			}
			$('#user_birthday').picker({
				title : "请选择出生年份",
				cols : [{
					textAlign : 'center',
					values : yearArr
				}],
				onChange : function(p, v, dv) {
					console.log('p:' + p, 'v:' + v, 'dv' + dv);
				},
				onClose : function(p, v, d) {
					console.log("close");
				}
			});
		}

		function setupMuiDatePicker() {
			var fullYear = new Date().getFullYear();
			$('#user_birthday').attr('data-options', '{"type":"date","beginYear":1900,"endYear":' + fullYear + '}');
			(function($mui) {
				$("#user_birthday").click(function() {
					var optionsJson = this.getAttribute('data-options') || '{}';
					// var id = $(this).attr('id');
					var options = JSON.parse(optionsJson);
					var picker = new $mui.DtPicker(options);
					picker.show(function(rs) {
						/*
						 * rs.value 拼合后的 value
						 * rs.text 拼合后的 text
						 * rs.y 年，可以通过 rs.y.vaue 和 rs.y.text 获取值和文本
						 * rs.m 月，用法同年
						 * rs.d 日，用法同年
						 * rs.h 时，用法同年
						 * rs.i 分（minutes 的第二个字母），用法同年
						 */
						$('#user_birthday').val(rs.text);
						/*
						 * 返回 false 可以阻止选择框的关闭
						 * return false;
						 */
						/*
						 * 释放组件资源，释放后将将不能再操作组件
						 * 通常情况下，不需要示放组件，new DtPicker(options) 后，可以一直使用。
						 * 当前示例，因为内容较多，如不进行资原释放，在某些设备上会较慢。
						 * 所以每次用完便立即调用 dispose 进行释放，下次用时再创建新实例。
						 */
						picker.dispose();
					});
				});
			})(mui);
		}

		function backClick() {
			api.closeWin();
		}

		function submitClick() {
			var telephone = $('#phonenumber').val();
			var qqnumber = $('#qqnumber').val();
			var usersex = $('#user_sex').val();
			var birthday = $('#user_birthday').val();
			if(telephone.length != 11){
			api.toast({
					msg : '手机号不正确',
					duration : 2000,
					location : 'bottom'
				});
				return;
			}
			//		if (telephone.length <= 0 || qqnumber.length <= 0 || usersex.length <= 0 || birthday.length <= 0) {
			if (usersex.length <= 0 || birthday.length <= 0) {
				api.toast({
					msg : '请完善信息后再提交',
					duration : 2000,
					location : 'bottom'
				});
				return;
			}
			//			//判断QQ号是否合法
			//			var reQQ = /^\d{4,}$/;
			//			if (!reQQ.test(qqnumber)) {
			//				api.toast({
			//					msg : '请输入合法的QQ号',
			//					duration : 2000,
			//					location : 'bottom'
			//				});
			//				return;
			//			}
			//			//判断手机号是否合法,验证130-139,150-159,180-189号码段的手机号码
			//			var rePhone = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
			//			if (!rePhone.test(telephone)) {
			//				api.toast({
			//					msg : '请输入合法的手机号',
			//					duration : 2000,
			//					location : 'bottom'
			//				});
			//				return;
			//			}
			var usexType = usersex == '男' ? 1 : 0;
			api.showProgress({
				style : 'default',
				animationType : 'fade',
				title : '正在提交',
				text : '请稍候...',
				modal : true
			});
			cfnetppPOST(urlEditact, {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid'),
				telephone : telephone,
				qqnumber : qqnumber,
				usersex : usexType,
				birthday : birthday
			}, false, function(data, status) {
				api.hideProgress();
//				alert("提交"+JSON.stringify(data));
				if (status == 'success') {
					if (data.status == 1) {
						api.toast({
							msg : '提交成功',
							duration : 2000,
							location : 'bottom'
						});
						setTimeout(function() {
							backClick();
						}, 1000);
					} else {
						api.toast({
							msg : '提交失败，请重试',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '提交失败，请检查网络',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}
	</script>
</html>
